package com.twohand.admin.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.twohand.admin.Entity.Menu;
import com.twohand.admin.Vo.MenuParentOptions;
import com.twohand.admin.Vo.SelectOptions;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface MenuMapper extends BaseMapper<Menu> {
    @Select("SELECT * from menu JOIN role_menu rm ON menu.id = rm.menu_id JOIN user_role ON user_role.role_id = rm.role_id AND user_role.user_id = #{id} ORDER BY weight DESC")
    List<Menu> getMenuListByUserId(Integer id);
    @Select("SELECT menu.id from menu JOIN role_menu rm ON menu.id = rm.menu_id JOIN user_role ON user_role.role_id = rm.role_id AND user_role.user_id = #{id} ORDER BY weight DESC")
    List<Integer> getAllMenuId(Integer id);

    @Select("SELECT menu.name from menu JOIN role_menu rm ON menu.id = rm.menu_id JOIN user_role ON user_role.role_id = rm.role_id AND user_role.user_id = #{id} WHERE menu.type = 2  ORDER BY weight DESC")
    List<String> getOprationMenu(Integer id);

    @Select("select * from menu where pid = #{parentId} order by weight desc")
    List<Menu> getMenuByParentId(Integer parentId);

    @Select("select id from menu")
    List<Integer> queryAllMenuId();

    @Select("select id as value,cname as label,type from menu where type != 2")
    List<MenuParentOptions> getOptions();

    @Select("select count(*) from menu where pid = #{id}")
    Integer getCountPidById(Integer id);
}
